class ScheduleController < ApplicationController
  def index
    if authorize
        #@course = Course.find_course
        if session[:loginrole] == "Admin"
            @dashboard = "Go to Gradebook"
        end
        @course_material = CourseMaterial.find(:first, :conditions => ["doc_type = 2"])
    end
  end
  
  def authorize 
      unless session[:loggedin] == true
          flash[:notice] = "Please log in" 
            redirect_to :controller => :login, :action => :index
            return false
        end
        return true 
    end 

    def add_schedule
        #recs = CourseMaterial.count
      #CourseMaterial.create(:title => params[:title], :document_url => 'some url', :document => params[:uploaded_document])
      @course_material = CourseMaterial.new(params[:course_material])
      @course_material.save
      @course_material.update_attribute(:doc_type, 2)
      CourseMaterial.delete_old_schedule
      redirect_to :controller => :schedule, :action => :index
   end
   
   def course_material
    @course_material = CourseMaterial.find(params[:id])
    send_data(@course_material.document,
              :filename => @course_material.filename,
              :type => @course_material.content_type,
              :disposition => "inline")
  end
end
